﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.IO;
using System.Threading;
using StartupTaskRunner.Configuration;
using StartupTaskRunner.Logging;
using System.Diagnostics.Contracts;
using System.Configuration;

namespace StartupTaskRunner
{
    internal class DevStorageDAL : IStorageDAL
    {

        public DevStorageDAL()
        {
        }

        public void UnZipFromBlobStorage(string containerName, string archiveName, string destinationFolder, bool overwrite)
        {
            string fullZipPath = Path.Combine(containerName, archiveName);

            Stream archiveStream = File.Open(fullZipPath, FileMode.Open, FileAccess.Read);

            ZipHelper.ExtractArchiveToFileSystem(archiveStream, destinationFolder, true);
        }

        public string GetConnectionString()
        {
            return ConfigurationManager.AppSettings["devConnectionString"];
        }

        public string Getcontainer()
        {
            return ConfigurationManager.AppSettings["devContainer"]; ;
        }

        public string GetconfigurationFilename()
        {
            return ConfigurationManager.AppSettings["devConfigurationFile"]; ;
        }

        public string DownloadFileContentFromBlob(string connectionString, string containerName, string configurationFilename)
        {
           return File.ReadAllText(Path.Combine(containerName, configurationFilename));
        }

        public void DownloadFileFromBlob(string destinationFolder, string containerName, string blobResource, bool overwrite)
        {
         
        }

        public void UploadFileToBlob(string sourceFile, string containerName, string blobResource)
        {
            if (!Directory.Exists(containerName))
            {
                Directory.CreateDirectory(containerName);
            }

            File.Copy(sourceFile, Path.Combine(containerName, blobResource));
        }
    }
}
